
import os
import wx


class DefaultPlatform:
    def __init__(self):
        pass

    def getFont(self):
        return wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Courier')

    def getFileName(self, name):
        return name

    def getDataDirectory(self, appdir=None, datadir=None):
        if appdir is None:
            appdir = os.environ.get('HOME')

        if appdir:
            appdata = os.path.join(appdir, datadir or '.aof')
            if not os.path.exists(appdata):
                try:
                    os.makedirs(appdata)
                except IOError:
                    pass

            if os.path.exists(appdata):
                return appdata

        return None

    def getAllFilesExtension(self):
        return 'All Files (*)|*'

    def hasStatusBar(self):
        """Supports the statusbar on the MDI window"""
        return True

    def hasChmfileSupport(self):
        """Supports the CHM help file"""
        return False


class WindowsPlatform(DefaultPlatform):
    def __init__(self):
        DefaultPlatform.__init__(self)

    def getFont(self):
        return wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL,
                       False, 'Courier New')

    def getFileName(self, name):
        if name:
            return name.lower().replace('/', '\\')
        else:
            return name

    def getDataDirectory(self):
        from win32com.shell import shell, shellcon
        appdir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

        return DefaultPlatform.getDataDirectory(
            self, appdir, 'AnalyzerforFiles')

    def getAllFilesExtension(self):
        return 'All Files (*.*)|*.*'

    def hasChmfileSupport(self):
        return True


class OsxPlatform(DefaultPlatform):
    def __init__(self):
        DefaultPlatform.__init__(self)

    def getFont(self):
        return wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Monaco')

    def hasStatusBar(self):
        return False


class Platform:
    @staticmethod
    def getInstance():
        if wx.Platform == '__WXMSW__':
            return WindowsPlatform()
        elif wx.Platform == '__WXMAC__':
            return OsxPlatform()
        else:
            return DefaultPlatform()
